/*
 * @Description: 系统模块
 * @Version: 1.0
 * @author: yxx
 * @Date: 2023-09-22 10:30:45
 * @LastEditors: zhanzghen
 * @LastEditTime: 2025-08-08 18:00:43
 */
import { SystemSpace } from "@/api/interface/system"
import { ResPage, Upload } from "@/api/interface/index"
import http from "@/api"
// ------------------部门管理------------------ //
// 部门管理 分页查询
export const getDeptPageListApi = (params: SystemSpace.DeptPageListQuery) => {
  return http.post<ResPage<SystemSpace.DeptPageList>>("/sys/dept/page", params, { loading: false })
}
// 部门管理 树状查询
export const getDeptTreeApi = (params: SystemSpace.DeptTreeQuery) => {
  return http.post<SystemSpace.DeptTree[]>("/sys/dept/tree", params, { loading: true })
}
// 部门管理 集合
export const getDeptCateApi = () => {
  return http.get<{ id: number; name: string }[]>("/sys/dept/cate", {}, { loading: true })
}
// 部门管理 所有
export const getDeptAllApi = () => {
  return http.get<SystemSpace.DeptPageList[]>("/sys/dept/list", {}, { loading: true })
}
// 部门管理 新增|修改
export const addDeptApi = (params: SystemSpace.DeptAdd) => {
  return http.post("/sys/dept/save", params, { loading: false })
}
// 部门管理 删除
export const deptTreeDeleteApi = (params: { id: number }) => {
  return http.post("/sys/dept/remove", params, { loading: false })
}
// ------------------菜单管理------------------ //
// 菜单管理 树状查询
export const getMenuTreeApi = (params: SystemSpace.MenuTreeQuery) => {
  return http.post<SystemSpace.MenuTree[]>("/sys/menu/tree", params, { loading: true })
}
// 菜单管理 新增|修改
export const saveMenuApi = (params: SystemSpace.MenuAdd) => {
  return http.post("/sys/menu/save", params, { loading: false })
}
// 菜单管理 删除
export const removeMenuApi = (params: { id: number }) => {
  return http.post("/sys/menu/remove", params, { loading: false })
}
// ------------------用户管理------------------ //
// 用户管理 分页查询
export const getUserPageListApi = (params: SystemSpace.UserPageListQuery) => {
  return http.post<ResPage<SystemSpace.UserPageList>>("/sys/user/page", params, { loading: false })
}
// 用户管理 集合
export const getUserCateApi = () => {
  return http.get<SystemSpace.UserCate[]>("/sys/user/list", {}, { loading: false })
}
// 用户管理 详情
export const getUserDetailApi = (params: { id: number }) => {
  return http.get<SystemSpace.UserDetail>("/sys/user/detail", params, { loading: false })
}
// 用户管理 保存
export const saveUserApi = (params: SystemSpace.UserAdd) => {
  return http.post<any>("/sys/user/save", params, { loading: false })
}
// 用户管理 删除
export const deleteUserApi = (params: { id: number }) => {
  return http.post("/sys/user/remove", params, { loading: false })
}
// 用户管理 修改个人信息
export const savePersonalUserApi = (params: SystemSpace.UserPersonal) => {
  return http.post<any>("/sys/login/modify/info", params, { loading: false })
}
// 用户管理 修改个人头像
export const savePersonalAvatarApi = (params: FormData) => {
  return http.post<Upload.ResFileUrl>("/sys/login/profile", params, { loading: false })
}
// ------------------角色管理------------------ //
// 角色管理 分页查询
export const getRolePageListApi = (params: SystemSpace.RolePageListQuery) => {
  return http.post<ResPage<SystemSpace.RolePageList>>("/sys/role/page", params, { loading: false })
}
// 角色管理 新增|修改
export const saveRoleApi = (params: SystemSpace.RoleAdd) => {
  return http.post("/sys/role/save", params, { loading: false })
}
// 角色管理 删除
export const deleteRoleApi = (params: { id: number }) => {
  return http.post("/sys/role/remove", params, { loading: false })
}
// 角色管理 管理根据角色id查询菜单ids
export const getRoleMenuIdsApi = (params: { id: number }) => {
  return http.post<number[]>("/sys/role/menuIds", params, { loading: false })
}
// 角色管理 所有
export const getRoleAllApi = () => {
  return http.get<SystemSpace.RoleCate[]>("/sys/role/cate", {}, { loading: false })
}
// ------------------日志管理------------------ //
// 操作日志 分页查询
export const getActionLogPageListApi = (params: SystemSpace.ActionLogPageListQuery) => {
  return http.post<ResPage<SystemSpace.ActionLogPageList>>("/sys/log/opt/page", params, { loading: false })
}
// 操作日志详情
export const actionLogDetailApi = (params: { id: number }) => {
  return http.get<SystemSpace.ActionLogDetail>("/sys/log/opt/detail", params, { loading: false })
}
// 登录日志 分页查询
export const getLoginLogPageListApi = (params: SystemSpace.LoginLogPageListQuery) => {
  return http.post<ResPage<SystemSpace.LoginLogPageList>>("/sys/log/login/page", params, { loading: false })
}
// 登录日志详情
export const loginLogDetailApi = (params: { id: number }) => {
  return http.get<SystemSpace.LoginLogDetail>("/sys/log/login/detail", params, { loading: false })
}

// ------------------参数管理------------------ //
// 参数管理 分页查询
export const configPage = (params: SystemSpace.ConfigPageQuery) => {
  return http.post<ResPage<SystemSpace.ConfigPage>>("/sys/config/page", params)
}
// 参数管理 新增/编辑
export const saveConfig = (params: SystemSpace.SaveConfig) => {
  return http.post<any>("/sys/config/add", params)
}

// 参数管理 删除
export const deleteConfig = (params: { id: number }) => {
  return http.post<any>("/sys/config/remove", params)
}

// ------------------字典管理------------------ //
//数据字典分页
export const dataDictionaryPage = (params: SystemSpace.DataDictionaryPageQuery) => {
  return http.post<ResPage<SystemSpace.DataDictionaryPage>>("sys/dictType/page", params)
}

//数据字典列表
export const dataDictionaryList = () => {
  return http.get<SystemSpace.DataDictionaryPage[]>("sys/dictType/list")
}

//新增/编辑数据字典
export const saveDataDictionary = (params: SystemSpace.SaveDataDictionary) => {
  return http.post<any>("sys/dictType/save", params)
}

//删除数据字典
export const deleteDataDictionary = (id: number) => {
  return http.get<any>(`sys/dictType/deleteByIds?ids=${id}`)
}

//数据字典详情分页
export const dataDictionaryDetailPage = (params: SystemSpace.DataDictionaryDetailPageQuery) => {
  return http.post<ResPage<SystemSpace.DataDictionaryDetailPage>>("sys/dictData/page", params)
}

// 新增/编辑数据字典详情
export const saveDataDictionaryDetail = (params: SystemSpace.SaveDataDictionaryDetail) => {
  return http.post<any>("sys/dictData/save", params)
}

//删除数据字典详情
export const deleteDataDictionaryDetail = (id: number) => {
  return http.get<any>(`sys/dictData/deleteByIds?ids=${id}`)
}

// 根据类型查询数据字典
export const dataDictionaryByType = (type: string) => {
  return http.get<SystemSpace.DataDictionaryByType[]>(`/sys/dictData/selectDictDataByType?dictType=${type}`, { loading: false })
}
// 计量设备字典
export const dataDictionaryMeter = () => {
  return http.get<{ [key: string]: number | string }>(`/sys/dictData/list/meter`)
}
// 通讯模式字典
export const dataDictionaryMode = () => {
  return http.get<{ [key: string]: number | string }>(`/sys/dictData/list/mode`)
}

// ------------------组织机构------------------ //

// 组织机构 树结构
export const organTree = () => {
  return http.get<SystemSpace.OrganTree[]>(`/sys/organ/tree`)
}
// 组织机构 新增/编辑
export const saveOrgan = (params: SystemSpace.SaveOrgan) => {
  return http.post<any>(`/sys/organ/save`, params)
}
// 组织机构 新增/编辑
export const deleteOrgan = (params: { id: number }) => {
  return http.post<any>(`/sys/organ/remove`, params)
}
// 根据层级查询厂区，产线数据
export const organByLevel = (level: 1 | 2) => {
  return http.get<SystemSpace.OrganByLevel[]>(`sys/organ/getOrganByLevel?level=${level}`)
}
